/*
ID: pallab81
PROG:
LANG: C++
*/

//"I have not failed, I have just found 10000 ways that won't work.

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i,st,ed) for(int i = st ; i < ed ; ++i )
#define fo(i,ed) foR( i , 0 , ed )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

class PowerGame {
public:
    string winner(int size0, int size1);
};

#define WIN 1
#define LOSE 0
#define ALAN 1

pair< int, int > dp[10000+5];
int vis[10000+5];

pair<int,int> go(int x) {
    if ( x < 1 ) {
        return mk(LOSE,0);
    }
    if ( vis[x]!=-1 ) {
        return dp[x];
    }
    vis[x]=1;
    int judge1=LOSE;

    int move1=0;
    int move2=0;

    bool virgin1=true;
    bool virgin2=true;

    for (int i=1;(i*i)<=x;++i) {
        pair<int,int> tmp = go(x-(i*i));
        tmp.s+=1;

        if (tmp.f==LOSE) {
            if ( virgin1 ) {
                judge1=WIN;
                virgin1=false;
                move1 = tmp.s;
            }
            else {
                move1 = min( move1,tmp.s);
            }
        }
        else {
            if ( virgin2 ) {
                virgin2=false;
                move2 = tmp.s;
            }
            else {
                move2 = max(move2,tmp.s);
            }
        }
    }
    if ( judge1==WIN ) {
        return dp[x]=mk(WIN,move1);
    }
    else {
        return dp[x]=mk(LOSE,move2);
    }
}
string PowerGame :: winner(int size0, int size1) {
    char buff[70];

    SET(vis,-1);
    pair<int,int> judge1 = go(size0);
    SET(vis,-1);
    pair<int,int> judge2 = go(size1);
    printf("%d %d\n%d %d\n",judge1.f,judge1.s,judge2.f,judge2.s);

    if ( judge1.f==judge2.f ) {
        if ( judge1.f==ALAN ) {
            sprintf(buff,"Alan will win after %d moves",min(judge1.s,judge2.s));
        }
        else {
            sprintf(buff,"Bob will win after %d moves",min(judge1.s,judge2.s));
        }
    }
    else {
        if ( judge1.s < judge2.s ) {
            if ( judge1.f==ALAN ) {
                sprintf(buff,"Alan will win after %d moves",judge1.s);
            }
            else {
                sprintf(buff,"Bob will win after %d moves",judge1.s);
            }
        }
        else {
            if ( judge2.f==ALAN ) {
                sprintf(buff,"Alan will win after %d moves",judge2.s);
            }
            else {
                sprintf(buff,"Bob will win after %d moves",judge2.s);
            }
        }

    }
    return (string)buff;
}
// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool KawigiEdit_RunTest(int testNum, int p0, int p1, bool hasAnswer, string p2) {
    cout << "Test " << testNum << ": [" << p0 << "," << p1;
    cout << "]" << endl;
    PowerGame *obj;
    string answer;
    obj = new PowerGame();
    clock_t startTime = clock();
    answer = obj->winner(p0, p1);
    clock_t endTime = clock();
    delete obj;
    bool res;
    res = true;
    cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
    if (hasAnswer) {
        cout << "Desired answer:" << endl;
        cout << "\t" << "\"" << p2 << "\"" << endl;
    }
    cout << "Your answer:" << endl;
    cout << "\t" << "\"" << answer << "\"" << endl;
    if (hasAnswer) {
        res = answer == p2;
    }
    if (!res) {
        cout << "DOESN'T MATCH!!!!" << endl;
    } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
        cout << "FAIL the timeout" << endl;
        res = false;
    } else if (hasAnswer) {
        cout << "Match :-)" << endl;
    } else {
        cout << "OK, but is it right?" << endl;
    }
    cout << "" << endl;
    return res;
}
int main() {
    bool all_right;
    all_right = true;

    int p0;
    int p1;
    string p2;

    {
        // ----- test 0 -----
        p0 = 4;
        p1 = 9;
        p2 = "Alan will win after 1 moves";
        all_right = KawigiEdit_RunTest(0, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 1 -----
        p0 = 4;
        p1 = 3;
        p2 = "Alan will win after 1 moves";
        all_right = KawigiEdit_RunTest(1, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 2 -----
        p0 = 2;
        p1 = 3;
        p2 = "Bob will win after 2 moves";
        all_right = KawigiEdit_RunTest(2, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 3 -----
        p0 = 7;
        p1 = 13;
        p2 = "Bob will win after 4 moves";
        all_right = KawigiEdit_RunTest(3, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 4 -----
        p0 = 2136;
        p1 = 1244;
        p2 = "Alan will win after 7 moves";
        all_right = KawigiEdit_RunTest(4, p0, p1, true, p2) && all_right;
        // ------------------
    }
    {
        // ----- test 5 -----
        p0 = 28;
        p1 = 17;
        p2 = "Alan will win after 7 moves";
        all_right = KawigiEdit_RunTest(5, p0, p1, true, p2) && all_right;
        // ------------------
    }
    {
        // ----- test 6 -----
        p0 = 502;
        p1 = 213;
        p2 = "Alan will win after 9 moves";
        all_right = KawigiEdit_RunTest(6, p0, p1, true, p2) && all_right;
        // ------------------
    }
    if (all_right) {
        cout << "You're a stud (at least on the example cases)!" << endl;
    } else {
        cout << "Some of the test cases had errors." << endl;
    }
    return 0;
}
// END KAWIGIEDIT TESTING


//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
// kate: indent-mode cstyle; space-indent on; indent-width 0; 
